﻿Public Class MainForm

    Dim filepath As String
    Dim ChinaLight() As String = {"Renault NC-31", "Vickers Mk. E Type B", "Type 2597 Chi-Ha", "M5A1 Stuart", "59-16", "WZ-131", "WZ-132"}
    Dim ChinaMedium() As String = {"Type T-34", "Type 58", "T-34-1", "T-34-2", "WZ-120", "121"}
    Dim ChinaHeavy() As String = {"IS-2", "110", "WZ-111 model 1-4", "113"}
    Dim ChinaPremium() As String = {"Type 62", "Type 59", "Type 59 G", "WZ-111"}
    Dim FrenchLight() As String = {"RenaultFT", "D1", "Hotchkiss H35", "AMX 38", "AMX 40", "ELC AMX", "AMX 12t", "AMX 13 75", "AMX 13 90"}
    Dim FrenchMedium() As String = {"D2", "Lorraine 40 t", "Bat Chatillon 25 t"}
    Dim FrenchHeavy() As String = {"B1", "BDR G1B", "ARL 44", "AMX M4(1945)", "AMX 50 100", "AMX 50 120", "AMX 50B"}
    Dim FrenchTD() As String = {"RenaultFT AC", "Renault UE 57", "Somua SAu-40", "S-35 CA", "ARL V39", "AMX AC Mle. 1946", "AMX AC Mle. 1948", "AMX 50 Foch", "AMX-50 Foch (155)"}
    Dim FrenchSPG() As String = {"RenaultBS", "Lorraine39 L AM", "AMX 105AM", "AMX 13 F3 AM", "Lorraine155 50", "Lorraine155 51", "Bat Chatillon 155"}
    Dim FrenchPremium() As String = {"FCM 50 t", "FCM36 PaK40", "105 leFH18B2"}
    Dim GermanLight() As String = {"Leichttraktor", "PzKpfw 35 (t)", "Pz.Kpfw. I", "PzKpfw II", "PzKpfw 38 (t)", "Panzer I Ausf. C", "Pz.Kpfw. II Ausf. G", "PzKpfw III Ausf. A", "PzKpfw 38 nA", "PzKpfw II Luchs", "VK 16.02 Leopard", "VK 28.01", "Aufklarungspanzer Panther"}
    Dim GermanMedium() As String = {"PzKpfw III", "PzKpfw III/IV", "PzKpfw IV", "VK 30.01 (H)", "VK 30.01 (P)", "VK 36.01 (H)", "PzKpfw V Panther", "VK 30.03 (D)", "Panther II", "E-50", "E-50 Ausf. M", "VK 20.01 (D)", "Indien Panzer", "Leopard Prototype A", "Leopard 1", "VK 30.01 (D)"}
    Dim GermanHeavy() As String = {"PzKpfw VI Tiger", "PzKpfw VI Tiger (P)", "PzKpfw VIB Tiger II", "VK 45.02 (P) Ausf. A", "E-75", "VK 45.02 (P) Ausf. B", "E-100", "Maus"}
    Dim GermanTD() As String = {"Panzerjager I", "Marder II", "Hetzer", "Stug III", "JagdPz IV", "Jagdpanther", "Ferdinand", "Jagdpanther II", "Jagdtiger", "JagdPz E-100"}
    Dim GermanSPG() As String = {"Sturmpanzer I Bison", "Sturmpanzer II", "Wespe", "Grille", "Hummel", "GW Panther", "GW Tiger", "GW Typ E"}
    Dim GermanPremium() As String = {"PzKpfw 38H735 (f)", "PzKpfw II Ausf. J", "T-15", "PzKpfw S35 739 (f)", "PzKpfw IV Hydraulic", "T-25", "PzKpfw IV Schmalturm", "PzKpfw V-IV", "PzKpfw V-IV Alpha", "Panther-M10", "PzKpfw B2 740 (f)", "Lowe", "Dicker Max", "8.8 cm PaK 43 Jagdtiger"}
    Dim UKLight() As String = {"Cruiser Mk. I", "Cruiser Mk. III", "Cruiser Mk. II", "Cruiser Mk. IV", "Covenanter", "Valentine", "Crusader"}
    Dim UKMedium() As String = {"Vickers Medium Mk. I", "Vickers Medium Mk. II", "Vickers Medium Mk. III", "Matilda", "Cromwell", "Comet", "Centurion Mk. I", "Centurion Mk. 7/1", "FV4202"}
    Dim UKHeavy() As String = {"Churchill I", "Churchill VII", "Black Prince", "Caernarvon", "Conqueror", "FV215b"}
    Dim UKTD() As String = {"Universal Carrier 2-pdr", "Valentine AT", "Alecto", "AT 2", "Churchill Gun Carrier", "AT 8", "AT 7", "AT 15", "Tortoise", "FV215b (183)"}
    Dim UKPremium() As String = {"Matilda Black Prince", "TOG II", "AT-15A"}
    Dim USALight() As String = {"T1 Cunningham", "M2 LT", "M3 Stuart", "M5 Stuart", "M24 Chaffee", "T21", "T71"}
    Dim USAMedium() As String = {"T2 MT", "M2 MT", "M3 Lee", "M4 Sherman", "M4A2E4", "M7", "M4A3E2", "M4A3E8", "T20", "M26 Pershing", "T69", "M46 Patton", "T54E1", "M48A1"}
    Dim USAHeavy() As String = {"T1 HT", "M6", "T29", "T32", "M103", "T110E5", "T57 HT"}
    Dim USATD() As String = {"T18", "T82", "M8A1", "T40", "M10 Wolverine", "T49", "M18 Hellcat", "M36 Jackson", "T25 AT", "T25/2", "T28", "T28 Prototype", "T30", "T95", "T110E3", "T110E4"}
    Dim USASPG() As String = {"T57", "M37", "M7 Priest", "M41", "M12", "M40/M43", "T92"}
    Dim USAPremium() As String = {"T1E6", "T2 LT", "M22 Locust", "MTLS-1G14", "Ram-II", "T26E4 Super Pershing", "T14", "M6A2E1", "T34"}
    Dim USSRLight() As String = {"MS-1", "BT-2", "T-26", "BT-7", "T-46", "A-20", "T-50", "T-50-2", "T-60", "T-70", "T-80"}
    Dim USSRMedium() As String = {"T-28", "T-34", "T-34-85", "KV-13", "T-43", "T-44", "T-54", "T-62A"}
    Dim USSRHeavy() As String = {"KV-1", "KV-1S", "KV-2", "T-150", "IS", "KV-3", "IS-3", "KV-4", "IS-8", "ST-I", "IS-4", "IS-7"}
    Dim USSRTD() As String = {"AT-1", "SU-76", "SU-85B", "SU-85", "SU-100", "SU-100M1", "SU-152", "ISU-152", "SU-101", "Object 704", "SU-122-54", "Object 263", "Object 268"}
    Dim USSRSPG() As String = {"SU-18", "SU-26", "SU-5", "SU-8", "S-51", "SU-14", "Object 212", "Object 261"}
    Dim USSRPremium() As String = {"Tetrarch", "BT-SV", "M3 Stuart Lend Lease", "T-127", "Valentine II", "A-32", "Matilda IV", "Churchill III", "KV-220", "KV-220 Beta-Test", "IS-6", "KV-5", "SU-85I", "SU-100Y", "SU-122-44"}
    Dim nonPremium As String = "	Non-Premium:"
    Dim Premium As String = "	Premium:"
    Dim light As String = "		Light:"
    Dim medium As String = "		Medium:"
    Dim heavy As String = "		Heavy:"
    Dim td As String = "		TD:"
    Dim spg As String = "		SPG:"
    Dim tankSpaces As String = "			"

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        filepath = "Player Data\" & txtPlayerName.Text & ".txt"
    End Sub

    Private Sub cboxCountry_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxCountry.SelectedIndexChanged
        ListUpdater()
        SearchTanks()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxTankType.SelectedIndexChanged
        ListUpdater()
        SearchTanks()
    End Sub

    Private Sub txtTankSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTankSearch.TextChanged
        ListUpdater()
        SearchTanks()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Try
            Dim item As New ListBox.SelectedObjectCollection(lboxNonAdded)
            lboxAdded.Items.AddRange(ArrayList.Adapter(item).ToArray)
            For x = lboxNonAdded.SelectedItems.Count - 1 To 0 Step -1
                lboxNonAdded.Items.Remove(lboxNonAdded.SelectedItems(x))
            Next
        Catch ex As Exception
            Exit Sub
        End Try

        If lboxNonAdded.Items.Count <> 0 Then lboxNonAdded.SelectedIndex = 0
    End Sub

    Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
        Try
            Dim item As New ListBox.SelectedObjectCollection(lboxAdded)
            lboxNonAdded.Items.AddRange(ArrayList.Adapter(item).ToArray)
            For x = lboxAdded.SelectedItems.Count - 1 To 0 Step -1
                lboxAdded.Items.Remove(lboxAdded.SelectedItems(x))
            Next
        Catch ex As Exception
            Exit Sub
        End Try

        If lboxAdded.Items.Count <> 0 Then lboxAdded.SelectedIndex = 0
    End Sub

    Private Sub txtPlayerName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPlayerName.TextChanged
        filepath = "Player Data\" & txtPlayerName.Text & ".txt"
        If System.IO.File.Exists(filepath) Then
            lblNoPlayer.Visible = False
        Else
            lblNoPlayer.Visible = True
        End If
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        UpdatePlayer()
    End Sub

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        LoadPlayer()
    End Sub

    Private Sub UpdatePlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdatePlayerToolStripMenuItem.Click
        UpdatePlayer()
    End Sub

    Private Sub LoadPlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadPlayerToolStripMenuItem.Click
        LoadPlayer()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If txtPlayerName.Text = "" Or System.IO.File.Exists(filepath) = False Then Exit Sub

        System.IO.File.Delete(filepath)
    End Sub

    Private Sub DeletePlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeletePlayerToolStripMenuItem.Click
        If txtPlayerName.Text = "" Or System.IO.File.Exists(filepath) = False Then Exit Sub

        System.IO.File.Delete(filepath)
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub WoTWikiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WoTWikiToolStripMenuItem.Click
        Process.Start("http://wiki.worldoftanks.com/Main_Page")
    End Sub

    Private Sub ChangelogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangelogToolStripMenuItem.Click
        Process.Start("https://code.google.com/p/wot-player-garage-tracker/source/browse/trunk/World%20of%20Tanks%20-%20Player%20Garage/Changelog.txt")
    End Sub

    Private Sub CheckForUpdatesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdatesToolStripMenuItem.Click
        Process.Start("https://code.google.com/p/wot-player-garage-tracker/downloads/list")
    End Sub

    Public Sub ListUpdater()
        lboxNonAdded.Items.Clear()
        If cboxCountry.SelectedItem Is "All" Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(ChinaLight)
                lboxNonAdded.Items.AddRange(ChinaMedium)
                lboxNonAdded.Items.AddRange(ChinaHeavy)
                lboxNonAdded.Items.AddRange(ChinaPremium)
                lboxNonAdded.Items.AddRange(FrenchLight)
                lboxNonAdded.Items.AddRange(FrenchMedium)
                lboxNonAdded.Items.AddRange(FrenchHeavy)
                lboxNonAdded.Items.AddRange(FrenchTD)
                lboxNonAdded.Items.AddRange(FrenchSPG)
                lboxNonAdded.Items.AddRange(FrenchPremium)
                lboxNonAdded.Items.AddRange(GermanLight)
                lboxNonAdded.Items.AddRange(GermanMedium)
                lboxNonAdded.Items.AddRange(GermanHeavy)
                lboxNonAdded.Items.AddRange(GermanTD)
                lboxNonAdded.Items.AddRange(GermanSPG)
                lboxNonAdded.Items.AddRange(GermanPremium)
                lboxNonAdded.Items.AddRange(UKLight)
                lboxNonAdded.Items.AddRange(UKMedium)
                lboxNonAdded.Items.AddRange(UKHeavy)
                lboxNonAdded.Items.AddRange(UKTD)
                lboxNonAdded.Items.AddRange(UKPremium)
                lboxNonAdded.Items.AddRange(USALight)
                lboxNonAdded.Items.AddRange(USAMedium)
                lboxNonAdded.Items.AddRange(USAHeavy)
                lboxNonAdded.Items.AddRange(USATD)
                lboxNonAdded.Items.AddRange(USASPG)
                lboxNonAdded.Items.AddRange(USAPremium)
                lboxNonAdded.Items.AddRange(USSRLight)
                lboxNonAdded.Items.AddRange(USSRMedium)
                lboxNonAdded.Items.AddRange(USSRHeavy)
                lboxNonAdded.Items.AddRange(USSRTD)
                lboxNonAdded.Items.AddRange(USSRSPG)
                lboxNonAdded.Items.AddRange(USSRPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(ChinaLight)
                lboxNonAdded.Items.AddRange(FrenchLight)
                lboxNonAdded.Items.AddRange(GermanLight)
                lboxNonAdded.Items.AddRange(UKLight)
                lboxNonAdded.Items.AddRange(USALight)
                lboxNonAdded.Items.AddRange(USSRLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(ChinaMedium)
                lboxNonAdded.Items.AddRange(FrenchMedium)
                lboxNonAdded.Items.AddRange(GermanMedium)
                lboxNonAdded.Items.AddRange(UKMedium)
                lboxNonAdded.Items.AddRange(USAMedium)
                lboxNonAdded.Items.AddRange(USSRMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(ChinaHeavy)
                lboxNonAdded.Items.AddRange(FrenchHeavy)
                lboxNonAdded.Items.AddRange(GermanHeavy)
                lboxNonAdded.Items.AddRange(UKHeavy)
                lboxNonAdded.Items.AddRange(USAHeavy)
                lboxNonAdded.Items.AddRange(USSRHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(FrenchTD)
                lboxNonAdded.Items.AddRange(GermanTD)
                lboxNonAdded.Items.AddRange(UKTD)
                lboxNonAdded.Items.AddRange(USATD)
                lboxNonAdded.Items.AddRange(USSRTD)
            ElseIf cboxTankType.SelectedItem Is "SPG" Then
                lboxNonAdded.Items.AddRange(FrenchSPG)
                lboxNonAdded.Items.AddRange(GermanSPG)
                lboxNonAdded.Items.AddRange(USASPG)
                lboxNonAdded.Items.AddRange(USSRSPG)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(ChinaPremium)
                lboxNonAdded.Items.AddRange(FrenchPremium)
                lboxNonAdded.Items.AddRange(GermanPremium)
                lboxNonAdded.Items.AddRange(UKPremium)
                lboxNonAdded.Items.AddRange(USAPremium)
                lboxNonAdded.Items.AddRange(USSRPremium)
            End If
        ElseIf cboxCountry.SelectedItem Is "China" Then
            If cboxTankType.selecteditem Is "All" Then
                lboxNonAdded.Items.AddRange(ChinaLight)
                lboxNonAdded.Items.AddRange(ChinaMedium)
                lboxNonAdded.Items.AddRange(ChinaHeavy)
                lboxNonAdded.Items.AddRange(ChinaPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(ChinaLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(ChinaMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(ChinaHeavy)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(ChinaPremium)
            End If
        ElseIf cboxCountry.selectedItem Is "France" Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(FrenchLight)
                lboxNonAdded.Items.AddRange(FrenchMedium)
                lboxNonAdded.Items.AddRange(FrenchHeavy)
                lboxNonAdded.Items.AddRange(FrenchTD)
                lboxNonAdded.Items.AddRange(FrenchSPG)
                lboxNonAdded.Items.AddRange(FrenchPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(FrenchLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(FrenchMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(FrenchHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(FrenchTD)
            ElseIf cboxTankType.SelectedItem Is "SPG" Then
                lboxNonAdded.Items.AddRange(FrenchSPG)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(FrenchPremium)
            End If
        ElseIf cboxCountry.selectedItem Is "Germany" Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(GermanLight)
                lboxNonAdded.Items.AddRange(GermanMedium)
                lboxNonAdded.Items.AddRange(GermanHeavy)
                lboxNonAdded.Items.AddRange(GermanTD)
                lboxNonAdded.Items.AddRange(GermanSPG)
                lboxNonAdded.Items.AddRange(GermanPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(GermanLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(GermanMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(GermanHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(GermanTD)
            ElseIf cboxTankType.SelectedItem Is "SPG" Then
                lboxNonAdded.Items.AddRange(GermanSPG)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(GermanPremium)
            End If
        ElseIf cboxCountry.selectedItem Is "U.K." Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(UKLight)
                lboxNonAdded.Items.AddRange(UKMedium)
                lboxNonAdded.Items.AddRange(UKHeavy)
                lboxNonAdded.Items.AddRange(UKTD)
                lboxNonAdded.Items.AddRange(UKPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(UKLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(UKMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(UKHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(UKTD)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(UKPremium)
            End If
        ElseIf cboxCountry.selectedItem Is "U.S.A." Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(USALight)
                lboxNonAdded.Items.AddRange(USAMedium)
                lboxNonAdded.Items.AddRange(USAHeavy)
                lboxNonAdded.Items.AddRange(USATD)
                lboxNonAdded.Items.AddRange(USASPG)
                lboxNonAdded.Items.AddRange(USAPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(USALight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(USAMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(USAHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(USATD)
            ElseIf cboxTankType.SelectedItem Is "SPG" Then
                lboxNonAdded.Items.AddRange(USASPG)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(USAPremium)
            End If
        ElseIf cboxCountry.selectedItem Is "U.S.S.R." Then
            If cboxTankType.SelectedItem Is "All" Then
                lboxNonAdded.Items.AddRange(USSRLight)
                lboxNonAdded.Items.AddRange(USSRMedium)
                lboxNonAdded.Items.AddRange(USSRHeavy)
                lboxNonAdded.Items.AddRange(USSRTD)
                lboxNonAdded.Items.AddRange(USSRSPG)
                lboxNonAdded.Items.AddRange(USSRPremium)
            ElseIf cboxTankType.SelectedItem Is "Light" Then
                lboxNonAdded.Items.AddRange(USSRLight)
            ElseIf cboxTankType.SelectedItem Is "Medium" Then
                lboxNonAdded.Items.AddRange(USSRMedium)
            ElseIf cboxTankType.SelectedItem Is "Heavy" Then
                lboxNonAdded.Items.AddRange(USSRHeavy)
            ElseIf cboxTankType.SelectedItem Is "TD" Then
                lboxNonAdded.Items.AddRange(USSRTD)
            ElseIf cboxTankType.SelectedItem Is "SPG" Then
                lboxNonAdded.Items.AddRange(USSRSPG)
            ElseIf cboxTankType.SelectedItem Is "Premium" Then
                lboxNonAdded.Items.AddRange(USSRPremium)
            End If
        End If
        For x = 0 To lboxAdded.Items.Count - 1
            For y = 0 To lboxNonAdded.Items.Count - 1
                If y > lboxNonAdded.Items.Count - 1 Then Exit For
                If lboxNonAdded.Items(y).ToString = lboxAdded.Items(x).ToString Then
                    lboxNonAdded.Items.RemoveAt(y)
                    y = y - 1
                End If
            Next
        Next
    End Sub

    Public Sub SearchTanks()
        If txtTankSearch.Text <> "" Then
            For i = 0 To lboxNonAdded.Items.Count - 1
                If i > lboxNonAdded.Items.Count - 1 Then Exit For
                If Not lboxNonAdded.Items(i).ToString.ToLower.Contains(Trim(LCase(txtTankSearch.Text))) Then
                    lboxNonAdded.Items.RemoveAt(i)
                    i = i - 1
                End If
            Next
        End If
    End Sub

    Public Sub UpdatePlayer()
        If txtPlayerName.Text = "" Then
            Exit Sub
        ElseIf System.IO.File.Exists(filepath) Then
            If MessageBox.Show("Are you sure you want to overwrite this file?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then Exit Sub
        End If
        If Not System.IO.Directory.Exists("Player Data") Then
            System.IO.Directory.CreateDirectory("Player Data")
        End If

        Dim lightChina As New List(Of String)
        Dim mediumChina As New List(Of String)
        Dim heavyChina As New List(Of String)
        Dim premiumChina As New List(Of String)
        Dim lightFrench As New List(Of String)
        Dim mediumFrench As New List(Of String)
        Dim heavyFrench As New List(Of String)
        Dim tdFrench As New List(Of String)
        Dim spgFrench As New List(Of String)
        Dim premiumFrench As New List(Of String)
        Dim lightGerman As New List(Of String)
        Dim mediumGerman As New List(Of String)
        Dim heavyGerman As New List(Of String)
        Dim tdGerman As New List(Of String)
        Dim spgGerman As New List(Of String)
        Dim premiumGerman As New List(Of String)
        Dim lightUK As New List(Of String)
        Dim mediumUK As New List(Of String)
        Dim heavyUK As New List(Of String)
        Dim tdUK As New List(Of String)
        Dim premiumUK As New List(Of String)
        Dim lightUSA As New List(Of String)
        Dim mediumUSA As New List(Of String)
        Dim heavyUSA As New List(Of String)
        Dim tdUSA As New List(Of String)
        Dim spgUSA As New List(Of String)
        Dim premiumUSA As New List(Of String)
        Dim lightUSSR As New List(Of String)
        Dim mediumUSSR As New List(Of String)
        Dim heavyUSSR As New List(Of String)
        Dim tdUSSR As New List(Of String)
        Dim spgUSSR As New List(Of String)
        Dim premiumUSSR As New List(Of String)

        For Each item In lboxAdded.Items
            For Each tank In ChinaLight
                If item.Trim Is tank Then lightChina.Add(tank)
            Next
            For Each tank In ChinaMedium
                If item.Trim Is tank Then mediumChina.Add(tank)
            Next
            For Each tank In ChinaHeavy
                If item.Trim Is tank Then heavyChina.Add(tank)
            Next
            For Each tank In ChinaPremium
                If item.Trim Is tank Then premiumChina.Add(tank)
            Next
            For Each tank In FrenchLight
                If item.Trim Is tank Then lightFrench.Add(tank)
            Next
            For Each tank In FrenchMedium
                If item.Trim Is tank Then mediumFrench.Add(tank)
            Next
            For Each tank In FrenchHeavy
                If item.Trim Is tank Then heavyFrench.Add(tank)
            Next
            For Each tank In FrenchTD
                If item.Trim Is tank Then tdFrench.Add(tank)
            Next
            For Each tank In FrenchSPG
                If item.Trim Is tank Then spgFrench.Add(tank)
            Next
            For Each tank In FrenchPremium
                If item.Trim Is tank Then premiumFrench.Add(tank)
            Next
            For Each tank In GermanLight
                If item.Trim Is tank Then lightGerman.Add(tank)
            Next
            For Each tank In GermanMedium
                If item.Trim Is tank Then mediumGerman.Add(tank)
            Next
            For Each tank In GermanHeavy
                If item.Trim Is tank Then heavyGerman.Add(tank)
            Next
            For Each tank In GermanTD
                If item.Trim Is tank Then tdGerman.Add(tank)
            Next
            For Each tank In GermanSPG
                If item.Trim Is tank Then spgGerman.Add(tank)
            Next
            For Each tank In GermanPremium
                If item.Trim Is tank Then premiumGerman.Add(tank)
            Next
            For Each tank In UKLight
                If item.Trim Is tank Then lightUK.Add(tank)
            Next
            For Each tank In UKMedium
                If item.Trim Is tank Then mediumUK.Add(tank)
            Next
            For Each tank In UKHeavy
                If item.Trim Is tank Then heavyUK.Add(tank)
            Next
            For Each tank In UKTD
                If item.Trim Is tank Then tdUK.Add(tank)
            Next
            For Each tank In UKPremium
                If item.Trim Is tank Then premiumUK.Add(tank)
            Next
            For Each tank In USALight
                If item.Trim Is tank Then lightUSA.Add(tank)
            Next
            For Each tank In USAMedium
                If item.Trim Is tank Then mediumUSA.Add(tank)
            Next
            For Each tank In USAHeavy
                If item.Trim Is tank Then heavyUSA.Add(tank)
            Next
            For Each tank In USATD
                If item.Trim Is tank Then tdUSA.Add(tank)
            Next
            For Each tank In USASPG
                If item.Trim Is tank Then spgUSA.Add(tank)
            Next
            For Each tank In USAPremium
                If item.Trim Is tank Then premiumUSA.Add(tank)
            Next
            For Each tank In USSRLight
                If item.Trim Is tank Then lightUSSR.Add(tank)
            Next
            For Each tank In USSRMedium
                If item.Trim Is tank Then mediumUSSR.Add(tank)
            Next
            For Each tank In USSRHeavy
                If item.Trim Is tank Then heavyUSSR.Add(tank)
            Next
            For Each tank In USSRTD
                If item.Trim Is tank Then tdUSSR.Add(tank)
            Next
            For Each tank In USSRSPG
                If item.Trim Is tank Then spgUSSR.Add(tank)
            Next
            For Each tank In USSRPremium
                If item.Trim Is tank Then premiumUSSR.Add(tank)
            Next
        Next

        Dim tankList As New System.Text.StringBuilder
        If lightChina.Count <> 0 Or mediumChina.Count <> 0 Or heavyChina.Count <> 0 Or premiumChina.Count <> 0 Then
            tankList.AppendLine("China:")
            If lightChina.Count <> 0 Or mediumChina.Count <> 0 Or heavyChina.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightChina.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightChina
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumChina.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumChina
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyChina.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyChina
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If premiumChina.Count <> 0 Then
                    tankList.AppendLine(Premium)
                    For Each tank In premiumChina
                        tankList.AppendLine("		" & tank.ToString)
                    Next
                End If
            End If
        End If
        If lightFrench.Count <> 0 Or mediumFrench.Count <> 0 Or heavyFrench.Count <> 0 Or tdFrench.Count <> 0 Or spgFrench.Count <> 0 Or premiumFrench.Count <> 0 Then
            tankList.AppendLine("France:")
            If lightFrench.Count <> 0 Or mediumFrench.Count <> 0 Or heavyFrench.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightFrench.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightFrench
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumFrench.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumFrench
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyFrench.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyFrench
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If tdFrench.Count <> 0 Then
                    tankList.AppendLine(td)
                    For Each tank In tdFrench
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If spgFrench.Count <> 0 Then
                    tankList.AppendLine(spg)
                    For Each tank In spgFrench
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
            End If
            If premiumFrench.Count <> 0 Then
                tankList.AppendLine(Premium)
                For Each tank In premiumFrench
                    tankList.AppendLine("		" & tank.ToString)
                Next
            End If
        End If
        If lightGerman.Count <> 0 Or mediumGerman.Count <> 0 Or heavyGerman.Count <> 0 Or tdGerman.Count <> 0 Or spgGerman.Count <> 0 Or premiumGerman.Count <> 0 Then
            tankList.AppendLine("Germany:")
            If lightGerman.Count <> 0 Or mediumGerman.Count <> 0 Or heavyGerman.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightGerman.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightGerman
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumGerman.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumGerman
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyGerman.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyGerman
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If tdGerman.Count <> 0 Then
                    tankList.AppendLine(td)
                    For Each tank In tdGerman
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If spgGerman.Count <> 0 Then
                    tankList.AppendLine(spg)
                    For Each tank In spgGerman
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If premiumGerman.Count <> 0 Then
                    tankList.AppendLine(Premium)
                    For Each tank In premiumGerman
                        tankList.AppendLine("		" & tank.ToString)
                    Next
                End If
            End If
        End If
        If lightUK.Count <> 0 Or mediumUK.Count <> 0 Or heavyUK.Count <> 0 Or tdUK.Count <> 0 Or premiumUK.Count <> 0 Then
            tankList.AppendLine("U.K.:")
            If lightUK.Count <> 0 Or mediumUK.Count <> 0 Or heavyUK.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightUK.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightUK
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumUK.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumUK
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyUK.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyUK
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If tdUK.Count <> 0 Then
                    tankList.AppendLine(td)
                    For Each tank In tdUK
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If premiumUK.Count <> 0 Then
                    tankList.AppendLine(Premium)
                    For Each tank In premiumUK
                        tankList.AppendLine("		" & tank.ToString)
                    Next
                End If
            End If
        End If
        If lightUSA.Count <> 0 Or mediumUSA.Count <> 0 Or heavyUSA.Count <> 0 Or tdUSA.Count <> 0 Or spgUSA.Count <> 0 Or premiumUSA.Count <> 0 Then
            tankList.AppendLine("U.S.A.:")
            If lightUSA.Count <> 0 Or mediumUSA.Count <> 0 Or heavyUSA.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightUSA.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightUSA
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumUSA.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumUSA
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyUSA.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyUSA
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If tdUSA.Count <> 0 Then
                    tankList.AppendLine(td)
                    For Each tank In tdUSA
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If spgUSA.Count <> 0 Then
                    tankList.AppendLine(spg)
                    For Each tank In spgUSA
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If premiumUSA.Count <> 0 Then
                    tankList.AppendLine(Premium)
                    For Each tank In premiumUSA
                        tankList.AppendLine("		" & tank.ToString)
                    Next
                End If
            End If
        End If
        If lightUSSR.Count <> 0 Or mediumUSSR.Count <> 0 Or heavyUSSR.Count <> 0 Or tdUSSR.Count <> 0 Or spgUSSR.Count <> 0 Or premiumUSSR.Count <> 0 Then
            tankList.AppendLine("U.S.S.R.:")
            If lightUSSR.Count <> 0 Or mediumUSSR.Count <> 0 Or heavyUSSR.Count <> 0 Then
                tankList.AppendLine(nonPremium)
                If lightUSSR.Count <> 0 Then
                    tankList.AppendLine(light)
                    For Each tank In lightUSSR
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If mediumUSSR.Count <> 0 Then
                    tankList.AppendLine(medium)
                    For Each tank In mediumUSSR
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If heavyUSSR.Count <> 0 Then
                    tankList.AppendLine(heavy)
                    For Each tank In heavyUSSR
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If tdUSSR.Count <> 0 Then
                    tankList.AppendLine(td)
                    For Each tank In tdUSSR
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If spgUSSR.Count <> 0 Then
                    tankList.AppendLine(spg)
                    For Each tank In spgUSSR
                        tankList.AppendLine(tankSpaces & tank.ToString)
                    Next
                End If
                If premiumUSSR.Count <> 0 Then
                    tankList.AppendLine(Premium)
                    For Each tank In premiumUSSR
                        tankList.AppendLine("		" & tank.ToString)
                    Next
                End If
            End If
        End If

        If System.IO.File.Exists(filepath) Then
            If System.IO.File.Exists(filepath & ".old") Then
                System.IO.File.Delete(filepath & ".old")
            End If
            System.IO.File.Copy(filepath, filepath & ".old")
            Dim fileWriter As New System.IO.StreamWriter(filepath)
            fileWriter.Write(tankList.ToString())
            fileWriter.Close()
        Else
            Dim fileWriter As New System.IO.StreamWriter(filepath, False)
            fileWriter.Write(tankList.ToString)
            fileWriter.Close()
        End If
        lblNoPlayer.Visible = False
    End Sub

    Public Sub LoadPlayer()
        If txtPlayerName.Text = "" Or System.IO.File.Exists(filepath) = False Then Exit Sub

        lboxAdded.Items.Clear()

        Dim fileReader() As String = System.IO.File.ReadAllLines(filepath)
        For Each line As String In fileReader
            For Each tank In ChinaLight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In ChinaMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In ChinaHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In ChinaPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchLight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchTD
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchSPG
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In FrenchPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanLight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanTD
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanSPG
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In GermanPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In UKLight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In UKMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In UKHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In UKTD
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In UKPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USALight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USAMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USAHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USATD
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USASPG
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USAPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRLight
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRMedium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRHeavy
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRTD
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRSPG
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
            For Each tank In USSRPremium
                If line.Trim = tank Then lboxAdded.Items.Add(tank)
            Next
        Next
        ListUpdater()
    End Sub
End Class
